unit uColFee;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, uParentBasic, cxGraphics, cxControls,
  cxLookAndFeels, cxLookAndFeelPainters, cxContainer, cxEdit, dxSkinsCore,
  dxSkinBlack, dxSkinBlue, dxSkinBlueprint, dxSkinCaramel, dxSkinCoffee,
  dxSkinDarkRoom, dxSkinDarkSide, dxSkinDevExpressDarkStyle,
  dxSkinDevExpressStyle, dxSkinFoggy, dxSkinGlassOceans, dxSkinHighContrast,
  dxSkiniMaginary, dxSkinLilian, dxSkinLiquidSky, dxSkinLondonLiquidSky,
  dxSkinMcSkin, dxSkinMoneyTwins, dxSkinOffice2007Black, dxSkinOffice2007Blue,
  dxSkinOffice2007Green, dxSkinOffice2007Pink, dxSkinOffice2007Silver,
  dxSkinOffice2010Black, dxSkinOffice2010Blue, dxSkinOffice2010Silver,
  dxSkinPumpkin, dxSkinSeven, dxSkinSevenClassic, dxSkinSharp, dxSkinSharpPlus,
  dxSkinSilver, dxSkinSpringTime, dxSkinStardust, dxSkinSummer2008,
  dxSkinTheAsphaltWorld, dxSkinsDefaultPainters, dxSkinValentine, dxSkinVS2010,
  dxSkinWhiteprint, dxSkinXmas2008Blue, Vcl.Menus, cxStyles, dxSkinscxPCPainter,
  cxCustomData, cxFilter, cxData, cxDataStorage, cxNavigator, Data.DB, cxDBData,
  Vcl.ActnList, cxGridLevel, cxClasses, cxGridCustomView, cxGridCustomTableView,
  cxGridTableView, cxGridDBTableView, cxGrid, Vcl.StdCtrls, cxButtons,
  cxGroupBox, cxMaskEdit, cxDropDownEdit, cxImageComboBox, cxDBEdit, cxTextEdit,
  Datasnap.DBClient, ClientRowSet;

type
  TFrmColFee = class(TFrmParentBasic)
    crsColFee: TClientRowSet;
    dsColFee: TDataSource;
    crsColFeeID: TStringField;
    crsColFeeSYS_ACCOUNT: TStringField;
    crsColFeeGROUP_CODE: TStringField;
    crsColFeeLOWEST_AMT: TFloatField;
    crsColFeeFEE: TFloatField;
    crsColFeeENABLED: TSmallintField;
    crsColFeeVERSION: TIntegerField;
    crsColFeeSTATUS: TSmallintField;
    crsColFeeREMARK: TStringField;
    crsColFeeMEMO: TStringField;
    crsColFeeCREATE_BY: TStringField;
    crsColFeeCREATE_DT: TStringField;
    crsColFeeUPDATE_DT: TStringField;
    crsColFeeCHANNEL_ID: TStringField;
    tvBasicLOWEST_AMT: TcxGridDBColumn;
    tvBasicFEE: TcxGridDBColumn;
    tvBasicENABLED: TcxGridDBColumn;
    tvBasicREMARK: TcxGridDBColumn;
    tvBasicUPDATE_DT: TcxGridDBColumn;
    Label1: TLabel;
    Label3: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    edtLowestamt: TcxDBTextEdit;
    edtFee: TcxDBTextEdit;
    edtRemark: TcxDBTextEdit;
    cxDBImageComboBox2: TcxDBImageComboBox;
    procedure crsColFeeBeforePost(DataSet: TDataSet);
    procedure crsColFeeNewRecord(DataSet: TDataSet);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    procedure InitForm;
    { Public declarations }
  end;

var
  FrmColFee: TFrmColFee;

implementation

{$R *.dfm}

uses uDm, ucommFunction, Console;

procedure TFrmColFee.crsColFeeBeforePost(DataSet: TDataSet);
begin
  inherited;
  crsColFee.FieldByName('update_dt').AsDateTime := Now;
  crsColFee.FieldByName('version').AsInteger := crsColFee.FieldByName('version').AsInteger + 1;
end;

procedure TFrmColFee.crsColFeeNewRecord(DataSet: TDataSet);
begin
  inherited;
  crsColFee.FieldByName('id').AsString := GetGUID;
  crsColFee.FieldByName('group_code').AsString := userInfo.groupCode;
  crsColFee.FieldByName('sys_account').AsString := userInfo.sysAccount;
  crsColFee.FieldByName('create_dt').AsDateTime := Now;
  crsColFee.FieldByName('enabled').AsInteger := 1;
end;

procedure TFrmColFee.FormCreate(Sender: TObject);
begin
  inherited;
  DataSet := crsColFee;
  KeyFieldName := 'id';
end;

procedure TFrmColFee.InitForm;
var
  tmpStr: string;
begin
  tmpStr := 'SELECT ' + GetClientRowSetColumns(crsColFee) + ' FROM BAS_COL_FEE_SETTING WHERE group_code=' + QuotedStr(userInfo.groupCode) +
    ' ORDER BY update_dt DESC';
  try
    crsColFee.DisableControls;
    crsColFee.Close;
    crsColFee.CommandText := tmpStr;
    crsColFee.Open;
  finally
    crsColFee.First;
    crsColFee.EnableControls;
  end;
end;

end.
